﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

Directory.CreateDirectory("C:\\osi\\bin");
Directory.CreateDirectory("C:\\osi\\InstallerTemp");
Directory.CreateDirectory("C:\\osi\\Temp");

if (args.Length == 2)
{
    if (args[0] == "install")
    {
        InstallerDownloader.cloneSoftWareInstaller(args[1] + ".ei");
        InstallerRunner.runInstaller(args[1]);
    }

    if (args[0] == "unisntall")
    {
        Directory.Delete(Path.Join("C:\\osi\\bin", args[1]));

        string currentPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine) ?? "";

        string pathToRemove = Path.Join("C:\\osi\\bin", args[1]);
        string[] paths = currentPath.Split(';');
        string updatedPath = string.Join(";", paths.Where(p => !p.Equals(pathToRemove, StringComparison.OrdinalIgnoreCase)));

        Environment.SetEnvironmentVariable("PATH", updatedPath, EnvironmentVariableTarget.Machine);
    }
}